<template>
  <view class="g-content">
    <uni-card
      class="card-course"
      :title="item['实验室地点']"
      :is-shadow="true"
      v-for="item in list"
      :id="item['实验室编号']"
    >
      <uni-forms border :modelValue="item">
          <uni-forms-item label="支持课程" name="course">
              <uni-easyinput :inputBorder="false"  v-model="item['支持课程']"></uni-easyinput>
          </uni-forms-item>
          <uni-forms-item label="容纳人数"  name="num">
              <uni-easyinput :inputBorder="false" v-model="item['容纳人数']"></uni-easyinput>
          </uni-forms-item>
          <button type="default" class="btn" @click="_alertLab(item['实验室编号'], item['支持课程'], item['容纳人数'])">保存修改</button>
      </uni-forms>
    </uni-card>
    <div style="height: 120rpx;"></div>
    <hans-tabber :list="tab" class="g-tabbar" style="position:fixed;bottom:0;width:100%;left:0;right:0;" :current="0"></hans-tabber>
  </view>
</template>

<script>
  import Adminer from '../../../api/Adminer.js';
  export default {
    data() {
      return {
        uid: this.$store.state.token.id,
        list: [],
        tab: [
          {
          	"text":"实验室",
          	"pagePath":"lab",
          	"iconPath":"../../../static/icon/task.png",
          	"selectedIconPath":"../../../static/icon/task.png"
          },
          {
          	"text":"实验室申请",
          	"pagePath":"apply",
          	"iconPath":"../../../static/icon/task.png",
          	"selectedIconPath":"../../../static/icon/task.png"
          }
        ]
      }
    },
    methods: {
      async _initList(){
        this.Test.log('实验室管理员-我的实验室',this.uid);
        const rm = (await Adminer.labor(this.uid));
        this.Test.log('实验室管理员-我的实验室',rm);
        if(rm[1]['statusCode'] == '200'){
          if(rm[1].data == [] || rm[1].data == ''){
            this.Toast.show('无实验室');
            this.list = [];
            return;
          }
          this.list = rm[1].data;
          //this.Toast.show('数据已加载');
        }
      },
      async _alertLab(id, course, num){
        uni.showLoading();
        const rm = (await Adminer.alertLabor(id, course, num));
        this.Test.log('实验室管理员-修改实验室',rm);
        if(rm[1]['statusCode'] == '200'){
          if(rm[1].data == [] || rm[1].data == ''){
            this.Toast.show('修改未知错误');
            uni.hideLoading();
            return;
          }
          if(rm[1].data['affectedRows'] == 1){
            this.Toast.show('修改成功');
          }
          else{
            this.Toast.show('修改失败');
          }
          uni.hideLoading();
        }
        this.Toast.show('网络连接失败，请检查网络或联系网络管理员');
        uni.hideLoading();
      }
    },
    onInit() {
      this.uid = this.$store.state.token.id;
    },
    onLoad() {
      this._initList();
    }
  }
</script>

<style scoped>
  .btn {
    height: 90rpx;
    width: 80%;
    margin-top: 20rpx;
    background-color: #EBD428;
    color: #707070;
  }
</style>
